/**
 * 提问表管理初始化
 */
var KnowledgeAnswers = {
    id: "KnowledgeAnswersTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
KnowledgeAnswers.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '消息内容', field: 'message', visible: true, align: 'center', valign: 'middle'},
            {title: '状态 1已解决 0未解决', field: 'state', visible: true, align: 'center', valign: 'middle'},
            {title: '技师ID', field: 'artificerId', visible: true, align: 'center', valign: 'middle'},
            {title: '消费ID', field: 'consumerId', visible: true, align: 'center', valign: 'middle'},
            {title: '提问时间', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
            {title: '解答时间', field: 'updateDate', visible: true, align: 'center', valign: 'middle'},
            {title: '提问的手机号', field: 'phone', visible: true, align: 'center', valign: 'middle'},
            {title: '知识库id', field: 'knowledgeId', visible: true, align: 'center', valign: 'middle'},
            {title: '图片1', field: 'imageA', visible: true, align: 'center', valign: 'middle'},
            {title: '图片2', field: 'imageB', visible: true, align: 'center', valign: 'middle'},
            {title: '图片3', field: 'imageC', visible: true, align: 'center', valign: 'middle'},
            {title: '图片4', field: 'imageD', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
KnowledgeAnswers.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        KnowledgeAnswers.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加提问表
 */
KnowledgeAnswers.openAddKnowledgeAnswers = function () {
    var index = layer.open({
        type: 2,
        title: '添加提问表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/knowledgeAnswers/knowledgeAnswers_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看提问表详情
 */
KnowledgeAnswers.openKnowledgeAnswersDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '提问表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/knowledgeAnswers/knowledgeAnswers_update/' + KnowledgeAnswers.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除提问表
 */
KnowledgeAnswers.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/knowledgeAnswers/delete", function (data) {
            Feng.success("删除成功!");
            KnowledgeAnswers.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("knowledgeAnswersId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询提问表列表
 */
KnowledgeAnswers.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    KnowledgeAnswers.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = KnowledgeAnswers.initColumn();
    var table = new BSTable(KnowledgeAnswers.id, "/knowledgeAnswers/list", defaultColunms);
    table.setPaginationType("client");
    KnowledgeAnswers.table = table.init();
});
